<?php

namespace app\admin\model\wanlshop;

use think\Model;


class Arrival extends Model
{

    

    

    // 表名
    protected $name = 'wanlshop_arrival';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'integer';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    protected $deleteTime = false;

    // 追加属性
    protected $append = [
        'nationality_data_text',
        'type_data_text',
        'status_text',
        'required_data_text'
    ];

    
    public function getNationalityDataList()
    {
        return ['1' => __('Nationality_data 1'), '2' => __('Nationality_data 2')];
    }

    public function getTypeDataList()
    {
        return ['1' => __('Type_data 1'), '2' => __('Type_data 2')];
    }

    public function getStatusList()
    {
        return ['1' => __('Status 1'), '0' => __('Status 0')];
    }

    public function getRequiredDataList()
    {
        return ['1' => __('Required_data 1'), '2' => __('Required_data 2'), '3' => __('Required_data 3'), '4' => __('Required_data 4')];
    }


    public function getNationalityDataTextAttr($value, $data)
    {
        $value = $value ?: ($data['nationality_data'] ?? '');
        $valueArr = explode(',', $value);
        $list = $this->getNationalityDataList();
        return implode(',', array_intersect_key($list, array_flip($valueArr)));
    }


    public function getTypeDataTextAttr($value, $data)
    {
        $value = $value ?: ($data['type_data'] ?? '');
        $valueArr = explode(',', $value);
        $list = $this->getTypeDataList();
        return implode(',', array_intersect_key($list, array_flip($valueArr)));
    }


    public function getStatusTextAttr($value, $data)
    {
        $value = $value ?: ($data['status'] ?? '');
        $list = $this->getStatusList();
        return $list[$value] ?? '';
    }


    public function getRequiredDataTextAttr($value, $data)
    {
        $value = $value ?: ($data['required_data'] ?? '');
        $valueArr = explode(',', $value);
        $list = $this->getRequiredDataList();
        return implode(',', array_intersect_key($list, array_flip($valueArr)));
    }

    protected function setNationalityDataAttr($value)
    {
        return is_array($value) ? implode(',', $value) : $value;
    }

    protected function setRequiredDataAttr($value)
    {
        return is_array($value) ? implode(',', $value) : $value;
    }

    protected function setTypeDataAttr($value)
    {
        return is_array($value) ? implode(',', $value) : $value;
    }


}
